package com.catarc.unityback.controller;

import com.catarc.unityback.entity.dto.AnimationPositionSingleFrameDTO;
import com.catarc.unityback.entity.dto.SaveAnimationSingleDTO;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
 * @author van
 * @date 2023/2/5 17:10
 */
@RestController
public class AnimationPositionSingleController {

    public static Map<String, List<AnimationPositionSingleFrameDTO>> singleMap = Maps.newHashMap();

    @GetMapping("/single/animation/add")
    public void addAnimation(@RequestParam("name") String name) {
        singleMap.put(name, Lists.newLinkedList());
    }

    @PostMapping("/single/animation/save")
    public void singleAnimationSave(@RequestBody SaveAnimationSingleDTO dto) {
        singleMap.put(dto.getAnimationName(), Lists.newLinkedList(dto.getFrames()));
    }

    @GetMapping("/single/animation/list/get")
    public Set<String> getAnimationList() {
        return singleMap.keySet();
    }

    @GetMapping("/single/animation/data/get")
    public List<AnimationPositionSingleFrameDTO> getAnimationData(@RequestParam("name") String name) {
        return Optional.ofNullable(singleMap.get(name)).orElse(Lists.newArrayList());
    }
}
